import 'package:flutter/material.dart';
import '../widget/keep_state.dart';

class Message extends StatefulWidget {
  const Message({Key? key}) : super(key: key);

  @override
  _MessageState createState() => _MessageState();
}

class _MessageState extends State<Message> with SingleTickerProviderStateMixin {
  late TabController _tabController;
  List<Map> tabs = [
    {'title': '志远', 'icon': const Icon(Icons.people)},
    {'title': '远哥', 'icon': const Icon(Icons.people)},
    {'title': '珊珊', 'icon': const Icon(Icons.people)},
  ];

  @override
  void initState() {
    _tabController = TabController(length: tabs.length, vsync: this);
    super.initState();
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: PreferredSize(
        preferredSize: const Size.fromHeight(80),
        child: AppBar(
          bottom: TabBar(
            tabs: tabs.map((item){
              return Tab(
                text: item['title'],
                icon: item['icon'],
              );
            }).toList(),
            controller: _tabController,
            // isScrollable: true,
          ),
        ),
      ),
      body: TabBarView(
        controller: _tabController,
        children: tabs.map((item){
          return KeepState(name: item['title'],);
          // return Text(item['title']);
        }).toList(),

      ),
    );
  }
}
